<template>
  <div>
    <h2>购物车</h2>
    <ul>
      <li v-for="item in cart" :key="item.id">
        {{ item.name }} - ￥{{ item.price }} - 数量：{{ item.quantity }}
        <button @click="removeFromCart(item)">-</button>
      </li>
    </ul>
    <p>总价：￥{{ totalPrice }}</p>
  </div>
</template>

<script>
import { mapState, mapGetters, mapMutations } from 'vuex';

export default {
  computed: {
    ...mapState(['cart']),
    ...mapGetters(['cartTotalPrice'])
  },
  methods: {
    ...mapMutations(['removeFromCart'])
  }
};
</script>